package dcc.service;

import java.util.List;

import dcc.model.CommonInfo;
import dcc.persistence.CommonInfoMapper;
import dcc.tools.Tools;

public class CommonInfoService extends BaseService {

	private CommonInfoMapper commonInfoMapper;

	public void setCommonInfoMapper(CommonInfoMapper commonInfoMapper) {
		this.commonInfoMapper = commonInfoMapper;
	}

	public CommonInfoService() {
		super(CommonInfoService.class);
	}

	public int save(CommonInfo commonInfo) {
		commonInfo.setINPUTTER(Tools.get().getUser().getUserName());
		if (commonInfo.getId() == 0) {
			return insert(commonInfo);
		} else {
			return update(commonInfo);
		}
	}

	private int insert(CommonInfo commonInfo) {
		commonInfoMapper.insert(commonInfo);
		return commonInfo.getId();
	}

	private int update(CommonInfo commonInfo) {
		commonInfoMapper.update(commonInfo);
		return commonInfo.getId();
	}

	public CommonInfo getCommonInfoBySBHAndLB(CommonInfo commonInfo) {
		return commonInfoMapper.getCommonInfoBySBHAndLB(commonInfo);
	}

	public List<CommonInfo> getAll() {
		return commonInfoMapper.getAll();
	}

	public List<CommonInfo> getRecordsBySBHOrXM(String key) {
		return commonInfoMapper.getRecordsBySBHOrXM(key);
	}

	public void deleteCommonInfoBySBHAndLB(CommonInfo commonInfo) {
		commonInfoMapper.deleteCommonInfoBySBHAndLB(commonInfo);
		
	}

	public List<CommonInfo> getCommonInfoByLB(String RCLB) {
		return commonInfoMapper.getCommonInfoByLB(RCLB);
	}
}
